// import { defaultconfig } from "../src/defaultconfig";
import { fetchinbrowser } from "../src/fetchinbrowser";
import { getlocalpathfrombaseurl } from "./getlocalpathfrombaseurl";

export default (baseurl: string): ((u: string) => Promise<string>) => {
    return async function fetchinpre(u: string): Promise<string> {
        const { promises } = await import("fs");

        if (u.startsWith(baseurl)) {
            const filepath = await getlocalpathfrombaseurl(u, baseurl);
            console.log(u, filepath);
            return (await promises.readFile(filepath)).toString();
        } else {
            return fetchinbrowser(u);
        }
    };
};
